Note
Click here to download the full example code
RecoBundles80 using AFQ API¶
An example using the AFQ API to run recobundles with the 80 bundle atlas.
import os.path as op
import plotly
from AFQ import api
import AFQ.data as afd
Get some example data¶
Retrieves Stanford HARDI dataset.
afd.organize_stanford_data(clear_previous_afq=True)
Out:
0%| | 0/5578 [00:00<?, ? MB/s]
0%| | 6/5578 [00:00<01:55, 48.37 MB/s]
0%| | 17/5578 [00:00<01:17, 71.79 MB/s]
1%| | 35/5578 [00:00<00:52, 104.60 MB/s]
1%|1 | 60/5578 [00:00<00:38, 141.87 MB/s]
2%|1 | 92/5578 [00:00<00:30, 182.77 MB/s]
2%|2 | 123/5578 [00:00<00:26, 204.66 MB/s]
3%|2 | 155/5578 [00:00<00:24, 220.92 MB/s]
3%|3 | 187/5578 [00:01<00:23, 231.97 MB/s]
4%|3 | 216/5578 [00:01<00:21, 245.80 MB/s]
4%|4 | 242/5578 [00:01<00:22, 239.15 MB/s]
5%|4 | 272/5578 [00:01<00:20, 254.30 MB/s]
5%|5 | 298/5578 [00:01<00:21, 244.43 MB/s]
6%|5 | 328/5578 [00:01<00:20, 258.54 MB/s]
6%|6 | 355/5578 [00:01<00:20, 249.02 MB/s]
7%|6 | 383/5578 [00:01<00:20, 257.17 MB/s]
7%|7 | 409/5578 [00:01<00:21, 245.06 MB/s]
8%|7 | 439/5578 [00:01<00:19, 259.18 MB/s]
8%|8 | 466/5578 [00:02<00:20, 249.34 MB/s]
9%|8 | 495/5578 [00:02<00:19, 257.77 MB/s]
9%|9 | 521/5578 [00:02<00:20, 248.05 MB/s]
10%|9 | 550/5578 [00:02<00:19, 256.66 MB/s]
10%|# | 576/5578 [00:02<00:20, 246.79 MB/s]
11%|# | 606/5578 [00:02<00:19, 259.67 MB/s]
11%|#1 | 633/5578 [00:02<00:19, 251.10 MB/s]
12%|#1 | 661/5578 [00:02<00:19, 257.73 MB/s]
12%|#2 | 687/5578 [00:02<00:19, 245.27 MB/s]
13%|#2 | 718/5578 [00:03<00:19, 247.91 MB/s]
13%|#3 | 745/5578 [00:03<00:19, 253.84 MB/s]
14%|#3 | 773/5578 [00:03<00:19, 248.20 MB/s]
14%|#4 | 799/5578 [00:03<00:19, 250.98 MB/s]
15%|#4 | 829/5578 [00:03<00:18, 251.98 MB/s]
15%|#5 | 855/5578 [00:03<00:18, 253.82 MB/s]
16%|#5 | 884/5578 [00:03<00:18, 250.33 MB/s]
16%|#6 | 910/5578 [00:03<00:18, 252.00 MB/s]
17%|#6 | 940/5578 [00:03<00:18, 251.94 MB/s]
17%|#7 | 967/5578 [00:04<00:17, 256.57 MB/s]
18%|#7 | 995/5578 [00:04<00:18, 249.92 MB/s]
18%|#8 | 1023/5578 [00:04<00:17, 257.29 MB/s]
19%|#8 | 1051/5578 [00:04<00:18, 251.33 MB/s]
19%|#9 | 1077/5578 [00:04<00:17, 253.46 MB/s]
20%|#9 | 1107/5578 [00:04<00:17, 251.35 MB/s]
20%|## | 1138/5578 [00:04<00:17, 252.54 MB/s]
21%|## | 1164/5578 [00:04<00:17, 253.54 MB/s]
21%|##1 | 1194/5578 [00:04<00:17, 254.47 MB/s]
22%|##1 | 1220/5578 [00:05<00:17, 254.48 MB/s]
22%|##2 | 1250/5578 [00:05<00:17, 252.52 MB/s]
23%|##2 | 1279/5578 [00:05<00:16, 261.87 MB/s]
23%|##3 | 1306/5578 [00:05<00:17, 249.78 MB/s]
24%|##3 | 1337/5578 [00:05<00:16, 250.78 MB/s]
25%|##4 | 1367/5578 [00:05<00:16, 262.33 MB/s]
25%|##4 | 1394/5578 [00:05<00:16, 250.31 MB/s]
26%|##5 | 1424/5578 [00:05<00:16, 249.03 MB/s]
26%|##6 | 1451/5578 [00:05<00:16, 253.84 MB/s]
27%|##6 | 1480/5578 [00:06<00:16, 251.57 MB/s]
27%|##7 | 1507/5578 [00:06<00:15, 255.29 MB/s]
28%|##7 | 1535/5578 [00:06<00:16, 249.98 MB/s]
28%|##8 | 1562/5578 [00:06<00:15, 254.93 MB/s]
29%|##8 | 1591/5578 [00:06<00:15, 252.12 MB/s]
29%|##9 | 1618/5578 [00:06<00:15, 256.39 MB/s]
30%|##9 | 1646/5578 [00:06<00:15, 250.37 MB/s]
30%|##9 | 1672/5578 [00:06<00:15, 252.55 MB/s]
31%|### | 1702/5578 [00:06<00:15, 249.44 MB/s]
31%|###1 | 1734/5578 [00:07<00:15, 250.42 MB/s]
32%|###1 | 1766/5578 [00:07<00:15, 252.16 MB/s]
32%|###2 | 1797/5578 [00:07<00:14, 255.33 MB/s]
33%|###2 | 1823/5578 [00:07<00:14, 255.78 MB/s]
33%|###3 | 1853/5578 [00:07<00:14, 250.71 MB/s]
34%|###3 | 1885/5578 [00:07<00:14, 252.01 MB/s]
34%|###4 | 1916/5578 [00:07<00:14, 250.61 MB/s]
35%|###4 | 1948/5578 [00:07<00:14, 251.87 MB/s]
35%|###5 | 1980/5578 [00:08<00:14, 252.74 MB/s]
36%|###6 | 2012/5578 [00:08<00:14, 253.47 MB/s]
37%|###6 | 2044/5578 [00:08<00:13, 253.82 MB/s]
37%|###7 | 2075/5578 [00:08<00:13, 251.87 MB/s]
38%|###7 | 2107/5578 [00:08<00:13, 252.65 MB/s]
38%|###8 | 2139/5578 [00:08<00:13, 253.87 MB/s]
39%|###8 | 2171/5578 [00:08<00:13, 254.05 MB/s]
39%|###9 | 2203/5578 [00:08<00:13, 254.16 MB/s]
40%|#### | 2235/5578 [00:09<00:13, 254.44 MB/s]
41%|#### | 2266/5578 [00:09<00:13, 251.55 MB/s]
41%|####1 | 2298/5578 [00:09<00:13, 252.02 MB/s]
42%|####1 | 2330/5578 [00:09<00:12, 252.97 MB/s]
42%|####2 | 2362/5578 [00:09<00:12, 253.28 MB/s]
43%|####2 | 2394/5578 [00:09<00:12, 254.04 MB/s]
43%|####3 | 2425/5578 [00:09<00:12, 251.96 MB/s]
44%|####4 | 2457/5578 [00:09<00:12, 252.86 MB/s]
45%|####4 | 2489/5578 [00:10<00:12, 251.78 MB/s]
45%|####5 | 2521/5578 [00:10<00:12, 252.75 MB/s]
46%|####5 | 2553/5578 [00:10<00:11, 253.80 MB/s]
46%|####6 | 2585/5578 [00:10<00:11, 253.52 MB/s]
47%|####6 | 2616/5578 [00:10<00:11, 252.87 MB/s]
47%|####7 | 2648/5578 [00:10<00:11, 253.37 MB/s]
48%|####8 | 2680/5578 [00:10<00:11, 253.73 MB/s]
49%|####8 | 2712/5578 [00:10<00:11, 252.72 MB/s]
49%|####9 | 2744/5578 [00:11<00:11, 252.82 MB/s]
50%|####9 | 2775/5578 [00:11<00:11, 252.78 MB/s]
50%|##### | 2802/5578 [00:11<00:10, 257.01 MB/s]
51%|##### | 2831/5578 [00:11<00:10, 251.47 MB/s]
51%|#####1 | 2862/5578 [00:11<00:10, 251.67 MB/s]
52%|#####1 | 2889/5578 [00:11<00:10, 255.74 MB/s]
52%|#####2 | 2918/5578 [00:11<00:10, 249.30 MB/s]
53%|#####2 | 2950/5578 [00:11<00:10, 251.06 MB/s]
53%|#####3 | 2982/5578 [00:12<00:10, 252.46 MB/s]
54%|#####3 | 3010/5578 [00:12<00:09, 259.62 MB/s]
54%|#####4 | 3037/5578 [00:12<00:10, 249.34 MB/s]
55%|#####4 | 3066/5578 [00:12<00:09, 260.16 MB/s]
55%|#####5 | 3093/5578 [00:12<00:09, 249.66 MB/s]
56%|#####5 | 3119/5578 [00:12<00:09, 252.44 MB/s]
56%|#####6 | 3148/5578 [00:12<00:09, 249.76 MB/s]
57%|#####6 | 3175/5578 [00:12<00:09, 254.95 MB/s]
57%|#####7 | 3204/5578 [00:12<00:09, 251.65 MB/s]
58%|#####7 | 3230/5578 [00:13<00:09, 252.51 MB/s]
58%|#####8 | 3260/5578 [00:13<00:09, 253.32 MB/s]
59%|#####8 | 3286/5578 [00:13<00:09, 254.00 MB/s]
59%|#####9 | 3315/5578 [00:13<00:08, 252.77 MB/s]
60%|#####9 | 3341/5578 [00:13<00:08, 252.38 MB/s]
60%|###### | 3371/5578 [00:13<00:08, 252.36 MB/s]
61%|###### | 3397/5578 [00:13<00:08, 254.27 MB/s]
61%|######1 | 3426/5578 [00:13<00:08, 251.39 MB/s]
62%|######1 | 3452/5578 [00:13<00:08, 252.43 MB/s]
62%|######2 | 3482/5578 [00:14<00:08, 254.14 MB/s]
63%|######2 | 3508/5578 [00:14<00:08, 253.98 MB/s]
63%|######3 | 3538/5578 [00:14<00:07, 255.54 MB/s]
64%|######3 | 3564/5578 [00:14<00:07, 254.28 MB/s]
64%|######4 | 3593/5578 [00:14<00:07, 253.28 MB/s]
65%|######4 | 3619/5578 [00:14<00:07, 252.38 MB/s]
65%|######5 | 3649/5578 [00:14<00:07, 253.80 MB/s]
66%|######5 | 3675/5578 [00:14<00:07, 254.10 MB/s]
66%|######6 | 3705/5578 [00:14<00:07, 254.22 MB/s]
67%|######6 | 3731/5578 [00:15<00:07, 254.84 MB/s]
67%|######7 | 3760/5578 [00:15<00:07, 252.29 MB/s]
68%|######7 | 3786/5578 [00:15<00:07, 253.53 MB/s]
68%|######8 | 3816/5578 [00:15<00:06, 253.73 MB/s]
69%|######8 | 3842/5578 [00:15<00:06, 254.16 MB/s]
69%|######9 | 3872/5578 [00:15<00:06, 251.61 MB/s]
70%|######9 | 3903/5578 [00:15<00:06, 250.40 MB/s]
71%|####### | 3935/5578 [00:15<00:06, 251.83 MB/s]
71%|#######1 | 3967/5578 [00:15<00:06, 251.94 MB/s]
72%|#######1 | 3999/5578 [00:16<00:06, 253.31 MB/s]
72%|#######2 | 4031/5578 [00:16<00:06, 252.02 MB/s]
73%|#######2 | 4062/5578 [00:16<00:05, 263.98 MB/s]
73%|#######3 | 4089/5578 [00:16<00:05, 255.46 MB/s]
74%|#######3 | 4118/5578 [00:16<00:05, 248.32 MB/s]
74%|#######4 | 4150/5578 [00:16<00:05, 250.01 MB/s]
75%|#######4 | 4182/5578 [00:16<00:05, 251.83 MB/s]
76%|#######5 | 4213/5578 [00:16<00:05, 253.08 MB/s]
76%|#######6 | 4241/5578 [00:17<00:05, 259.72 MB/s]
77%|#######6 | 4269/5578 [00:17<00:05, 250.42 MB/s]
77%|#######7 | 4301/5578 [00:17<00:05, 252.60 MB/s]
78%|#######7 | 4333/5578 [00:17<00:04, 253.72 MB/s]
78%|#######8 | 4364/5578 [00:17<00:04, 251.88 MB/s]
79%|#######8 | 4392/5578 [00:17<00:04, 259.14 MB/s]
79%|#######9 | 4420/5578 [00:17<00:04, 252.28 MB/s]
80%|#######9 | 4448/5578 [00:17<00:04, 259.49 MB/s]
80%|######## | 4475/5578 [00:17<00:04, 249.99 MB/s]
81%|######## | 4503/5578 [00:18<00:04, 257.61 MB/s]
81%|########1 | 4531/5578 [00:18<00:04, 251.02 MB/s]
82%|########1 | 4558/5578 [00:18<00:03, 255.50 MB/s]
82%|########2 | 4586/5578 [00:18<00:03, 249.96 MB/s]
83%|########2 | 4614/5578 [00:18<00:03, 257.79 MB/s]
83%|########3 | 4642/5578 [00:18<00:03, 251.55 MB/s]
84%|########3 | 4669/5578 [00:18<00:03, 256.34 MB/s]
84%|########4 | 4698/5578 [00:18<00:03, 252.02 MB/s]
85%|########4 | 4725/5578 [00:18<00:03, 255.61 MB/s]
85%|########5 | 4753/5578 [00:19<00:03, 249.62 MB/s]
86%|########5 | 4781/5578 [00:19<00:03, 257.54 MB/s]
86%|########6 | 4809/5578 [00:19<00:03, 250.94 MB/s]
87%|########6 | 4836/5578 [00:19<00:02, 254.27 MB/s]
87%|########7 | 4864/5578 [00:19<00:02, 250.53 MB/s]
88%|########7 | 4892/5578 [00:19<00:02, 255.45 MB/s]
88%|########8 | 4920/5578 [00:19<00:02, 249.57 MB/s]
89%|########8 | 4947/5578 [00:19<00:02, 254.72 MB/s]
89%|########9 | 4975/5578 [00:19<00:02, 252.95 MB/s]
90%|########9 | 5001/5578 [00:20<00:02, 252.07 MB/s]
90%|######### | 5031/5578 [00:20<00:02, 248.21 MB/s]
91%|######### | 5063/5578 [00:20<00:02, 250.40 MB/s]
91%|#########1| 5094/5578 [00:20<00:01, 255.91 MB/s]
92%|#########1| 5120/5578 [00:20<00:01, 254.47 MB/s]
92%|#########2| 5150/5578 [00:20<00:01, 249.01 MB/s]
93%|#########2| 5182/5578 [00:20<00:01, 251.17 MB/s]
93%|#########3| 5214/5578 [00:20<00:01, 252.23 MB/s]
94%|#########4| 5246/5578 [00:20<00:01, 253.54 MB/s]
95%|#########4| 5277/5578 [00:21<00:01, 251.05 MB/s]
95%|#########5| 5309/5578 [00:21<00:01, 252.62 MB/s]
96%|#########5| 5341/5578 [00:21<00:00, 253.19 MB/s]
96%|#########6| 5373/5578 [00:21<00:00, 252.95 MB/s]
97%|#########6| 5405/5578 [00:21<00:00, 254.13 MB/s]
97%|#########7| 5436/5578 [00:21<00:00, 252.29 MB/s]
98%|#########8| 5468/5578 [00:21<00:00, 253.25 MB/s]
99%|#########8| 5500/5578 [00:21<00:00, 253.95 MB/s]
99%|#########9| 5532/5578 [00:22<00:00, 253.79 MB/s]
100%|#########9| 5564/5578 [00:22<00:00, 253.82 MB/s]
100%|##########| 5578/5578 [00:22<00:00, 250.42 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 4215.38 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 3581.81 MB/s]
0%| | 0/71 [00:00<?, ? MB/s]
8%|8 | 6/71 [00:00<00:01, 50.82 MB/s]
24%|##3 | 17/71 [00:00<00:00, 75.45 MB/s]
48%|####7 | 34/71 [00:00<00:00, 106.04 MB/s]
86%|########5 | 61/71 [00:00<00:00, 153.98 MB/s]
100%|##########| 71/71 [00:00<00:00, 140.49 MB/s]
0%| | 0/4 [00:00<?, ? MB/s]
100%|##########| 4/4 [00:00<00:00, 64.46 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 3795.75 MB/s]
Set tractography parameters (optional)¶
We make this tracking_params which we will pass to the AFQ object which specifies that we want 50,000 seeds randomly distributed in the white matter.
We only do this to make this example faster and consume less space.
tracking_params = dict(n_seeds=50000,
random_seeds=True,
rng_seed=42)
Initialize an AFQ object:¶
We specify seg_algo as reco80 in segmentation_params. This tells the AFQ object to perform RecoBundles using the 80 bundles atlas in the segmentation step.
myafq = api.AFQ(bids_path=op.join(afd.afq_home,
'stanford_hardi'),
dmriprep='vistasoft',
segmentation_params={"seg_algo": "reco80"},
tracking_params=tracking_params)
Out:
Downloading https://templateflow.s3.amazonaws.com/tpl-MNI152NLin2009cAsym/tpl-MNI152NLin2009cAsym_res-01_T1w.nii.gz
0%| | 0.00/13.4k [00:00<?, ?B/s]
0%| | 33.0/13.4k [00:00<00:59, 224B/s]
1%|1 | 135/13.4k [00:00<00:26, 497B/s]
5%|4 | 628/13.4k [00:00<00:07, 1.79kB/s]
18%|#7 | 2.39k/13.4k [00:00<00:01, 5.76kB/s]
49%|####8 | 6.54k/13.4k [00:00<00:00, 15.6kB/s]
68%|######8 | 9.09k/13.4k [00:00<00:00, 17.3kB/s]
97%|#########7| 13.0k/13.4k [00:00<00:00, 23.3kB/s]
13.4kB [00:00, 14.5kB/s]
Downloading https://templateflow.s3.amazonaws.com/tpl-MNI152NLin2009cAsym/tpl-MNI152NLin2009cAsym_res-01_desc-brain_mask.nii.gz
0%| | 0.00/155 [00:00<?, ?B/s]
16%|#6 | 25.0/155 [00:00<00:00, 166B/s]
93%|#########2| 144/155 [00:00<00:00, 532B/s]
156B [00:00, 515B/s]
Visualizing bundles and tract profiles:¶
This would run the script and visualize the bundles using the plotly interactive visualization, which should automatically open in a new browser window.
bundle_html = myafq.viz_bundles(export=True, n_points=50)
plotly.io.show(bundle_html[0])